package com.ooono.factorytest.view;

public class CoordsCalc {
	/**
	 * Calculate unknown coordinate depend on coordinate of circle,radius,radians between unknown coordinate and the initial point
	 * @param cirX
	 *            x coordinate of circle
	 * @param cirY
	 *            y coordinate of circle
	 * @param radius
	 *            radius of circle
	 * @param arcAngle
	 *            radians between unknown coordinate and the initial point
	 * @return coordinate array of unknown coordinate
	 */
	public static float[] calcArcEndPointXY(float cirX, float cirY,
			float radius, float arcAngle) {
		float posX = cirX;
		float posY = cirY;
		float cirAngle = (float) ((arcAngle / Math.PI) * 180);
		if (cirAngle < 90) {
			posX = cirX + (float) (Math.cos(arcAngle)) * radius;
			posY = cirY + (float) (Math.sin(arcAngle)) * radius;
		} else if (cirAngle == 90) {
			posX = cirX;
			posY = cirY + radius;
		} else if (cirAngle > 90 && cirAngle < 180) {
			arcAngle = (float) (Math.PI * (180 - cirAngle) / 180.0);
			posX = cirX - (float) (Math.cos(arcAngle)) * radius;
			posY = cirY + (float) (Math.sin(arcAngle)) * radius;
		} else if (cirAngle == 180) {
			posX = cirX - radius;
			posY = cirY;
		} else if (cirAngle > 180 && cirAngle < 270) {
			arcAngle = (float) (Math.PI * (cirAngle - 180) / 180.0);
			posX = cirX - (float) (Math.cos(arcAngle)) * radius;
			posY = cirY - (float) (Math.sin(arcAngle)) * radius;
		} else if (cirAngle == 270) {
			posX = cirX;
			posY = cirY - radius;
		} else {
			arcAngle = (float) (Math.PI * (360 - cirAngle) / 180.0);
			posX = cirX + (float) (Math.cos(arcAngle)) * radius;
			posY = cirY - (float) (Math.sin(arcAngle)) * radius;
		}
		return new float[] { posX, posY };
	}
}